#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[200005] {}, ans = -1;
int n;
unordered_set<ll> s;

void dfs(int la) {
    ll lr = -1, lb = -1, ans1 = 0;
    for (int i = 1; i <= n; i++) {
        if (s.count(a[i])) {
            if (a[i] == lr) {
                ans1 += a[i];
            }
            lr = a[i];
        } else {
            if (a[i] == lb) {
                ans1 += a[i];
            }
            lb = a[i];
        }
    }
    ans = max(ans, ans1);
    for (int i = la + 1; i <= n; i++) {
        if (!s.count(a[i])) {
            s.insert(a[i]);
            dfs(i);
            s.erase(a[i]);
        }
    }
}

int main() {
    //ios::sync_with_stdio(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    scanf("%d", &t);
    for (int z = 1; z <= t; z++) {
        memset(a, 0, sizeof(a));
        ans = -1;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
        }
        dfs(0);
        printf("%lld\n", ans);
    }

    return 0;
}
//give me 20 points please
